function! s:dispatch() abort
    if !exists("g:loaded_dispatch")
        try
            packadd vim-dispatch
        catch /.*/
            echoerr v:exception
        endtry
    endif
    if exists("g:loaded_dispatch") && g:loaded_dispatch
        return v:true
    endif
    return v:false
endfunction 

function! s:on_write_commit_message() abort
    " silent! echo "bdelete! " . bufname("%") 
    " | Git push
endfunction

function! api#fugitive#init()
    " vim-fugitive" {{{
    if !exists('g:loaded_fugitive')
        try
            packadd vim-fugitive
        catch /.*/
        endtry
    endif
    if exists('g:loaded_fugitive') && g:loaded_fugitive
        autocmd BufWritePost *.git/COMMIT_EDITMSG call s:on_write_commit_message()
        nnoremap <m-g>      :Git<cr>
        nnoremap <leader>g  :Git<cr>
        let g:space_keymap = get(g:,                      'space_keymap', {})
        let g:space_keymap.g = get(g:space_keymap,        'g', { 'name': '+git',
                    \             'a'   : [':Git add %',  'add'],
                    \             's'   : [':Git status', 'status'],
                    \             'c'   : [':Git commit', 'commit'],
                    \             'd'   : [':Git diff',   'diff'],
                    \             'g'   : [':Git',        'git'],
                    \             'p'   : [':Git push',   'push'],
                    \             'l'   : [':Git pull',   'pull'],
                    \             '.'   : [':Git add .',  'add-cwd']
                    \           })
    endif
    " }}}
endfunction
